package com.arron.state;
//正常状态
public class NormalState extends AccountState {
    public NormalState(Account account) {
        super.acc = account;
    }

    public NormalState(AccountState state) {
        super.acc = state.acc;
    }

    @Override
    public void deposit(double amount) {
        super.acc.setBalance(super.acc.getBalance() + amount);
        this.stateCheck();
    }

    @Override
    public void withdraw(double amount) {
        super.acc.setBalance(super.acc.getBalance() - amount);
        this.stateCheck();
    }

    @Override
    public void computerInterest() {
        System.out.println("正常状态，无须支付利息！");
    }

    @Override
    public void stateCheck() {
        if (super.acc.getBalance() > -2000 && super.acc.getBalance() <= 0) {
            super.acc.setState(new OverDraftState(this));
        } else if (super.acc.getBalance() == -2000) {
            super.acc.setState(new RestrictedState(this));
        } else if (super.acc.getBalance() < -2000) {
            System.out.println("操作受限！");
        }

    }
}
